<template>
    <div class="notify-setting-comp">
        <bk-form
            v-if="subscription"
            ref="notifyForm"
            class="new-ui-form"
            form-type="vertical"
            :label-width="580"
            :model="subscription"
            :rules="notifyRules"
        >
            <bk-form-item property="types" :label="$t('settings.noticeType')" error-display-type="normal" :required="true">
                <bk-checkbox-group :value="subscription.types" @change="value => updateSubscription('types', value)">
                    <bk-checkbox v-for="item in noticeList" :key="item.id" :value="item.value">
                        {{ item.name }}
                    </bk-checkbox>
                </bk-checkbox-group>
            </bk-form-item>
            <bk-form-item :label="$t('settings.additionUser')">
                <staff-input
                    :handle-change="(name, value) => subscription.users = value.join(',')"
                    :value="subscription.users.split(',').filter(Boolean)"
                    :placeholder="$t('settings.additionUserPlaceholder')">
                </staff-input>
            </bk-form-item>
            <bk-form-item property="content" :label="$t('settings.noticeContent')" error-display-type="normal" :required="true">
                <bk-input
                    type="textarea"
                    :value="subscription.content"
                    @change="value => updateSubscription('content', value)"
                />
            </bk-form-item>

            <bk-form-item class="checkbox-item">
                <atom-checkbox style="width: auto"
                    :handle-change="updateSubscription"
                    name="detailFlag"
                    :text="$t('settings.pipelineLink')"
                    :desc="$t('settings.pipelineLinkDesc')"
                    :value="subscription.detailFlag">
                </atom-checkbox>
            </bk-form-item>
            
            <bk-form-item
                v-if="subscription.types.includes('WEWORK') || subscription.types.includes('RTX')"
                class="checkbox-item"
            >
                <atom-checkbox
                    style="width: auto"
                    name="wechatGroupFlag"
                    :text="$t('settings.enableGroup')"
                    :desc="groupIdDesc"
                    :handle-change="updateSubscription"
                    :value="subscription.wechatGroupFlag">
                </atom-checkbox>
            </bk-form-item>
            <template v-if="(subscription.types.includes('WEWORK') || subscription.types.includes('RTX')) && subscription.wechatGroupFlag">
                <bk-form-item :label="$t('settings.groupIdLabel')">
                    <group-id-selector
                        class="item-groupid"
                        :handle-change="updateSubscription"
                        name="wechatGroup"
                        :value="subscription.wechatGroup"
                        :placeholder="$t('settings.groupIdTips')"
                        icon-class="icon-question-circle"
                        desc-direction="top">
                    </group-id-selector>
                </bk-form-item>
                <bk-form-item class="checkbox-item">
                    <atom-checkbox
                        style="width: auto;"
                        name="wechatGroupMarkdownFlag"
                        :text="$t('settings.wechatGroupMarkdownFlag')"
                        :handle-change="updateSubscription"
                        :value="subscription.wechatGroupMarkdownFlag">
                    </atom-checkbox>
                </bk-form-item>
            </template>
        </bk-form>
    </div>
</template>

<script>
    import GroupIdSelector from '@/components/atomFormField/groupIdSelector'
    import StaffInput from '@/components/atomFormField/StaffInput'
    import AtomCheckbox from '@/components/atomFormField/AtomCheckbox'
    export default {
        name: 'notify-setting',
        components: {
            GroupIdSelector,
            StaffInput,
            AtomCheckbox
        },
        props: {
            subscription: Object,
            updateSubscription: Function
        },
        data () {
            return {
                notifyRules: {
                    types: [
                        {
                            message: this.$t('requiredSelectItem'),
                            trigger: 'blur',
                            validator: function (val) {
                                return val.length >= 1
                            }
                        }
                    ],
                    content: [
                        {
                            required: true,
                            message: this.$t('requiredItem'),
                            trigger: 'blur'
                        }
                    ]
                }
            }
        },
        computed: {
            noticeList () {
                return [
                    { id: 4, name: this.$t('settings.emailNotice'), value: 'EMAIL' },
                    { id: 1, name: this.$t('settings.rtxNotice'), value: 'WEWORK' },
                    { id: 5, name: this.$t('settings.voice'), value: 'VOICE' }
                    // { id: 2, name: this.$t('settings.wechatNotice'), value: 'WECHAT' },
                    // { id: 3, name: this.$t('settings.smsNotice'), value: 'SMS' }
                ]
            },
            groupIdDesc () {
                return this.$t('settings.groupIdDesc')
            }
        }
    }
</script>

<style lang="scss">
    .notify-setting-comp {
        .bk-form .bk-form-content {
            min-height: 24px;
        }
        .bk-form-item.checkbox-item .bk-form-content {
            min-height: 18px;
            line-height: 18px;
        }
        .bk-form-checkbox {
            display: inline-block;
            padding: 0;
            width: auto;
            margin-right: 24px;
        }
        .notify-setting-no-data {
            vertical-align: top;
            font-size: 12px;
            color: #63656e;
        }
    }
</style>
